package lainey.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * 各种错误界面
 */
public class ErrorHintView extends RelativeLayout {

    private TextView mTvText;
    private ImageView mIvResources;

    public ErrorHintView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public ErrorHintView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public ErrorHintView(Context context) {
        super(context);
        init();
    }

    private void init() {
        Context context = getContext();
        View view = View.inflate(context, R.layout.ui_common_error, this);
        mTvText = view.findViewById(R.id.tv_text);
        mIvResources = view.findViewById(R.id.iv_resources);

        setVisibility(GONE);
    }

    public void failed() {
        show(R.drawable.ui_common_failed, R.string.ui_common_failed);
    }

    public void network() {
        show(R.drawable.ui_common_network, R.string.ui_common_network);
    }

    public void noData() {
        show(R.drawable.ui_common_data, R.string.ui_common_data);
    }

    public void develop() {
        show(R.drawable.ui_common_develope, R.string.ui_hint_develop);
    }

    public void show(int drawableResId, int textResId) {
        setVisibility(VISIBLE);
        mTvText.setText(textResId);
        mIvResources.setImageResource(drawableResId);
    }


}
